<template>
	<!-- 客户添加 -->
	<div>
		<div class="edit-top">
			添加信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">客户信息</div>
			<div class="edit-item">
				<label>姓名</label><input v-model="info.chineseName"  type="text" />
			</div>
			<div class="edit-item">
				<label>证件类型</label>
				<el-radio v-for='item in dict.identityType' :key='item.value' v-model="info.identityType" :label="item.value">{{item.type}}</el-radio>
			</div>
			<div class="edit-item">
				<label>证件号码</label><input v-model="info.identityNum" type="text" />
			</div>
			<div class="edit-item">
				<label>性别</label>
				<el-radio v-for='item in dict.sex' :key='item.value' v-model="info.sex" :label="item.value">{{item.type}}</el-radio>
			</div>
			<div class="edit-item">
				<label>年龄</label><input  v-model="info.age" type="number" />
			</div>
			<div class="edit-item">
				<label>所属企业</label><select v-model="info.enterpriseId">
					<option v-for="item in enterprise_list" :value="item.id">{{item.enterpriseName}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>所属角色</label>				
				<span v-if="role_list.length <= 0">未设置角色</span>
				<template>
				  <el-checkbox-group v-model="info.roleIds">
				    <el-checkbox v-for='item in role_list' :key='item.id' :label="item.id">{{item.roleName}}</el-checkbox>
				  </el-checkbox-group>
				</template>
			</div>
			<div class="edit-item">
				<label>邮箱</label><input v-model="info.email" type="text" />
			</div>
			
			
			<div class="edit-item">
				<label>联系手机</label><input v-model="info.mobileNum" type="text" />
			</div>
			<!-- <div class="edit-item">
				<label>客户状态</label><select v-model="info.clientStatus">
					<option v-for='item in dict.clientStatus' :value="item.value">{{item.type}}</option>
				</select>
			</div> -->
			<div class="edit-title">用户信息</div>
			<div class="edit-item">
				<label>用户名</label><input v-model="info.sysUserDto.userName" type="text" />
			</div>
			<div class="edit-item">
				<label>密码</label><input v-model="info.sysUserDto.userPassword" type="text" />
			</div>
			<div class="edit-item">
				<label>用户状态</label><select v-model="info.sysUserDto.userStatus">
					<option v-for='item in dict.userStatus' :value="item.value">{{item.type}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>数据权限</label>
				<el-radio v-for='item in dict.dataAuth' :key='item.value' v-model="info.dataAuth" :label="item.value">{{item.type}}</el-radio>
			</div>
		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	let _this;
	export default {
		data() {
			return {
				dict: '',
				enterprise_list: [],
				role_list: [],
				
				info: {
					chineseName: '',
					enterpriseId: '',
					sex:'0',
					email: '',
					// clientStatus:0,
					"identityType": "0",
					"identityNum": "",
					mobileNum: '',
					idCard: '',
					jobStatus: 0,
					roleIds: [],
					dataAuth:"0",
					"sysUserDto":{
						"userName": "",
						"userPassword": "",
						"userStatus": 0,
					}
				},
			}
		},
		created() {
			_this = this;
		},
		mounted() {
			this.get_dict();
			this.get_enterprise_list();
			this.get_role_list();
		},
		methods: {
			get_dict(){
				this.$axios.get(this.$global.serverIp + 'admin/dict/findDict?keyword=sysClient')
				  .then(function (res) {
					  if(res != '')
						_this.dict = res.data;
				  })
			},
			get_enterprise_list(){
				this.$axios.post(this.$global.serverIp + 'admin/sysEnterprise/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							_this.enterprise_list = res.data.list;
							_this.info.enterpriseId = _this.enterprise_list[0].id;
						}
				
					})
			},
			get_role_list() {
				this.$axios.post(this.$global.serverIp + 'admin/sysRole/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							_this.role_list = res.data.list;
						}
				
					})
			},
			change_data(list) {
				var data = [];
				var length = list.length;
				for (var i = 0; i < length; i++) {
					var e = {};
					e.id = list[i].id;
					e.label = list[i].roleName;
					data.push(e);
					this.opendata.push(list[i].id);
				}
				return data;
			},
			save() {
				if (this.info.chineseName == "") {
					this.$popup.open('人员姓名不能为空');
					return;
				}
				if (this.info.roleIds.length <= 0) {
					this.$popup.open('所属角色不能为空');
					return;
				}
				if (this.info.mobileNum == '') {
					this.$popup.open('联系手机不能为空');
					return;
				}
				if (this.info.identityNum == '') {
					this.$popup.open('证件号不能为空');
					return;
				}
				if (this.info.sysUserDto.userName == '') {
					this.$popup.open('用户名不能为空');
					return;
				}
				if (this.info.sysUserDto.password == '') {
					this.$popup.open('密码不能为空');
					return;
				}
				this.$axios.post(this.$global.serverIp + 'jianeng-admin/sysClient/add', _this.info)
					.then(function(res) {
						if (res != '') {
							_this.success('添加成功');
						}
					})
			},
			success(content) {
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						_this.$emit("saveAdd", 2);
					}
				});
			},
			
			cancel() {
				this.$emit("saveAdd", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
